package logic

import (
	"context"
	"errors"
	"meituan_srv/model/redisinit"

	"meituan_srv/internal/svc"
	"meituan_srv/meituan"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartCountLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartCountLogic {
	return &CartCountLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 计算
func (l *CartCountLogic) CartCount(in *meituan.CartCountRequest) (*meituan.CartCountResponse, error) {
	// todo: add your logic here and delete this line

	count, f, err := redisinit.CartCount(in.UserId)
	if err != nil {
		logx.Error("计算失败")
		return nil, errors.New("计算失败")
	}
	return &meituan.CartCountResponse{
		Count: int64(count),
		Sum:   float32(f),
	}, nil
}
